package com.example.afinal;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

   public class ProvinceAdapter extends RecyclerView.Adapter<com.example.afinal.ProvinceAdapter.ProvinceViewHolder> {

        private List<Province> provinceList;
        private Context context;

        public ProvinceAdapter(List<Province> provinceList) {
            this.provinceList = provinceList;
            this.context = context;
        }

        @NonNull
        @Override
        public ProvinceViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_province, parent, false);
            return new ProvinceViewHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull ProvinceViewHolder holder, int position) {
            Province province = provinceList.get(position);
            holder.provinceNameTextView.setText(province.getName());
            holder.provinceCodeTextView.setText(province.getCode());
        }

        @Override
        public int getItemCount() {
            return provinceList.size();
        }

        public static class ProvinceViewHolder extends RecyclerView.ViewHolder {
            TextView provinceNameTextView;
            TextView provinceCodeTextView;

            public ProvinceViewHolder(@NonNull View itemView) {
                super(itemView);
                provinceNameTextView = itemView.findViewById(R.id.provinceNameTextView);
                provinceCodeTextView = itemView.findViewById(R.id.provinceCodeTextView);
            }
        }




    }


